﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;

namespace Assist
{
	public class SingleGridFilter : ISelectionFilter
	{
		public bool AllowElement(Element elem)
		{
			if (typeof(Grid) == elem.GetType())
			{
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(elem.Document);
				IList<Element> list = filteredElementCollector.OfClass(typeof(MultiSegmentGrid)).ToElements();
				foreach (Element element in list)
				{
					MultiSegmentGrid multiSegmentGrid = (MultiSegmentGrid)element;
					foreach (ElementId elementId in multiSegmentGrid.GetGridIds())
					{
						if (elementId.Equals(elem.Id))
						{
							return false;
						}
					}
				}
				return true;
			}
			return false;
		}

		public bool AllowReference(Reference reference, XYZ pos)
		{
			return false;
		}
	}
}
